cls
set more off
global destination = "XXXX"	/* INPUT: DESTINATION FOLDER */
global sourcefile = "XXXX"	/* INPUT: SOURCE FILE */
cd "$destination"  


********************************************************************************************************
********************************************************************************************************
***							COSTS (Table 6)
********************************************************************************************************
********************************************************************************************************
global list_indexes = "RegIn_Regulations RegIn_Responses RegIn_Time"
global controls_firm = "Assets TobinQ CF MTB Leverage"

clear
use "$sourcefile" 
gen Burden = .
xtset gvkey year 
eststo clear
foreach outcome of varlist COGS SGA {
	preserve
	keep if `outcome'!=.
	foreach index of global list_indexes {
		replace Burden = `index'
		noisily display "`index'"
		eststo: reghdfe `outcome' L.(Burden $controls_firm), absorb(i.year#i.ff48  i.gvkey) vce(cluster gvkey)
	}
	restore 
}
noisily esttab using "costs.tex", replace se b(3) booktabs nogap /*
		*/ obslast star(* 0.10 ** 0.05 *** 0.01) varwidth(25) /*
		*/ 	stats(N r2, fmt(%12.0gc %12.2fc) labels("Obs." "\(R^{2}\)"))  /*
		*/ drop(*cons*) /*
		*/ varlabels(L.Burden "\(RegIn\)" L.Assets "\(Assets\)" L.Leverage "\(Leverage\)" L.TobinQ "\(TobinQ\)" L.CF "\(CF\)" L.CTA "\(CTA\)" L.MTB "\(MTB\)" L.Sales "\(Sales\)")


********************************************************************************************************
********************************************************************************************************
***							MANAGING THE COSTS (Table 7)
********************************************************************************************************
********************************************************************************************************
global controls_firm = "Assets TobinQ CF MTB"
clear
use "$sourcefile" 
gen Burden = RegIn_Regulations
xtset gvkey year 
eststo clear
quietly foreach outcome of varlist CTA I_DebtIssu I_EquityIssu MarketLeverage Lobby_any GR_Labor RD3 {
	preserve
	keep if `outcome'!=.
	if regexm("`outcome'","Lobby")==1 {
		*keep if Lobby_ever==1
		*keep if year>=1999
	}
	noisily eststo: reghdfe `outcome' L.(Burden $controls_firm), absorb(i.year#i.ff48 i.gvkey)  vce(cluster gvkey)
	noisily summ `outcome' if e(sample)==1
	restore
}

noisily esttab using "managing intensity.tex", replace se b(3) booktabs nogap /*
		*/ obslast star(* 0.10 ** 0.05 *** 0.01) varwidth(25) /*
		*/ 	stats(N r2, fmt(%12.0gc %12.2fc) labels("Obs." "\(R^{2}\)"))  /*
		*/ keep(*Burden *Assets) /*
		*/ varlabels(L.Burden "\(RegIn\)" L.Assets "\(Assets\)" L.Leverage "\(Leverage\)" L.TobinQ "\(TobinQ\)" L.CF "\(CF\)" L.CTA "\(CTA\)" L.MTB "\(MTB\)")
*/

********************************************************************************************************
********************************************************************************************************
***							INVESTMENT (Table 8)
********************************************************************************************************
********************************************************************************************************
global controls_firm = "Assets TobinQ CF MTB Leverage KZ Capital"
global list_indexes = "RegIn_Regulations RegIn_Responses RegIn_Time"

clear
use "$sourcefile" 
keep if relevant==1
gen Burden = .
xtset gvkey year 
eststo clear
gen Outcome = Investment2
* Investment1 = scaled capx (divided by assets) 
* Investment2 = scaled capx (divided by ppegt)
* Investment3 = ((compppegt-L.compppegt)+(invt-L.invt))/(L.compat)

foreach index of global list_indexes {
	replace Burden = `index'
	noisily display "`index'"
	eststo: reghdfe Outcome L.(Burden $controls_firm), absorb(i.year#i.ff48 i.gvkey)  vce(cluster gvkey)
}


foreach index of global list_indexes {
	replace Burden = `index'
	noisily display "`index'"
	eststo: reghdfe Outcome L.(Burden c.FC#c.Burden $controls_firm), absorb(i.year#i.ff48 i.gvkey)  vce(cluster gvkey)
}


foreach index of global list_indexes {
	replace Burden = `index'
	noisily display "`index'"
	eststo: reghdfe Outcome L.(Burden c.CapIntense#c.Burden $controls_firm), absorb(i.year#i.ff48 i.gvkey)  vce(cluster gvkey)
}


noisily esttab using "Investment (channels).tex", replace se b(3) booktabs nogap /*
		*/ obslast star(* 0.10 ** 0.05 *** 0.01) varwidth(25) /*
		*/ 	stats(N r2, fmt(%12.0gc %12.2fc) labels("Obs." "\(R^{2}\)"))  /*
		*/ keep(*Burden* *Assets*)  order(*Burden*) /*
		*/ varlabels(L.Burden "\(RegIn\)" cL.FC#cL.Burden "\(FC\cdot RegIn\)" cL.Large#cL.Burden "\(Large\cdot RegIn\)" cL.CapIntense#cL.Burden "\(IR\cdot RegIn\)" L.Assets "\(Assets\)" L.Leverage "\(Leverage\)" L.TobinQ "\(TobinQ\)" L.CF "\(CF\)" L.CTA "\(CTA\)" L.MTB "\(MTB\)" L.KZ "\(KZ\)" L.Capital "\(Capital\)" )





